<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
import Chart from "./chart.vue";
import { getKnowMainCreate } from '../../../../api/know'
export default {
  data() {
    return {
      drawTiming: null,
      cdata: {
        year: null,
        weekCategory: [],
        maxData: 9500,
        // weekMaxData: [9500, 9500, 9500, 9500, 9500, 9500, 9500],
        weekLineData: [9384, 1928, 3941, 8294, 1938, 9173, 6482],
      },
    };
  },
  components: {
    Chart,
  },
  mounted() {
    // this.drawTimingFn();
    this.setData();
    this.getKnowMainCreate()
  },
  beforeDestroy() {
    clearInterval(this.drawTiming);
  },
  methods: {
    getKnowMainCreate(){
      getKnowMainCreate().then((res)=>{
        console.log(res)
        let lineList = []
        let dateList = []
        res.forEach(item => {
          lineList.push(item.count)
          dateList.push(item.date)
        });
        this.cdata.weekCategory = dateList
        this.cdata.weekLineData = lineList

      })
    },
    drawTimingFn() {
      this.setData();
      this.drawTiming = setInterval(() => {
        this.setData();
      }, 6000);
    },
    setData() {
      // 清空轮询数据
      this.cdata.weekCategory = [];

      let dateBase = new Date();
      this.cdata.year = dateBase.getFullYear();
      // 周数据
      // for (let i = 0; i < 7; i++) {
      //   // 日期
      //   let date = new Date();
      //   this.cdata.weekCategory.unshift(
      //     [date.getMonth() + 1, date.getDate() - i].join("/")
      //   );
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>